import type {IColumnsOption} from 'vc';
import {
  INDEX,
} from '@/utils/tableColumn';
import {toF9} from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    {...INDEX},
    {
      field: 'companyName',
      title: '发行机构',
      width: 270,
      fixed: 'left',
      headerAlign: 'center',
      sortBy: 'companyName',
      slots: {
        default: ({row}) => {
          const content = row.highlight?.companyName ? row.highlight?.companyName : row.companyName;
          if (row.companyId) {
            return <a title={row.companyName} class="companyName"
                      onClick={() => toF9(row.companyId)}
                      v-html={content}></a>;
          } else {
            return <span title={row.companyName || ''} v-html={content || '-'}></span>;
          }
        }
      }
    },
    {
      field: 'certificationDate',
      title: '认证日期',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'certificationDate'
    },
    {
      field: 'certificationResult',
      title: '认证结果',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'certificationResult'
    },
    {
      field: 'certificationResultsDescription',
      title: '认证结果描述',
      align: 'center',
      // sortable: true,
      width: 250,
      sortBy: 'certificationResultsDescription',
      showOverflow: 'title'
    },
    {
      field: 'stockCnt',
      title: '存量只数',
      align: 'center',
      // sortable: true,
      sortBy: 'stockCnt',
      width: 110,
      formatter: ({row}) => {
        return row.stockCnt ? row.stockCnt + '只' : '-';
      }
    },
    {
      field: 'stockIssuingScale',
      title: '存量规模',
      align: 'center',
      // sortable: true,
      sortBy: 'stockIssuingScale',
      width: 110,
      formatter: ({row}) => {
        return row.stockIssuingScale ? row.stockIssuingScale + '亿' : '-';
      }
    },
    {
      field: 'totalCnt',
      title: '累计发行数量',
      align: 'center',
      // sortable: true,
      sortBy: 'totalCnt',
      width: 110,
      slots: {
        default: ({row}) => {
          if (row.totalCnt) {
            return (
              <div>
                <a onClick={() => bondReleaseDetailFn(row)}>{row.totalCnt}只</a>
                <br/>
              </div>)

          } else {
            return (<span>-</span>)
          }
        }
      }
    },
    {
      field: 'totalIssuingScale',
      title: '累计发行规模',
      align: 'center',
      // sortable: true,
      sortBy: 'totalIssuingScale',
      width: 110,
      formatter: ({row}) => {
        return row.totalIssuingScale ? row.totalIssuingScale + '亿' : '-';
      }
    },
  ]);
  // 发行详情弹窗
  const showBondReleaseDetail = ref(false);
  const bondReleaseDetails = ref([]);

  const bondReleaseDetailFn = (data) => {
    showBondReleaseDetail.value = true;
    bondReleaseDetails.value = data;
  };

  return {
    columns,
    showBondReleaseDetail,
    bondReleaseDetails
  };
}
